import { Sequelize } from 'sequelize';

// 初始化 Sequelize 实例

export const sequelize = new Sequelize('dbtext', 'root', '123456', {
  host: 'localhost',
  dialect: 'mysql'  // 可选: 'mysql', 'sqlite', 'postgres', 'mssql'
  // storage: './userdb'
});

// 初始化数据库
(async () => {
  // 清空原数据库
  // await sequelize.sync({ force: true });
  await sequelize.sync();
})();

// 测试数据库连接
async function testConnection() {
  try {
    await sequelize.authenticate();
    console.log('Connection has been established successfully.');
  } catch (error) {
    console.error('Unable to connect to the database:', error);
  }
}

testConnection();

